﻿namespace DimensionsHelper.LanguageService.Syntax;

public class DmsProperty : Declaration
{
    private Expression? _value;

    internal DmsProperty(Identifier name, SyntaxNode? parent) :
        base(SyntaxKinds.DmsProperty, SyntaxToken.Default, name, parent)
    {
    }

    public Expression? Value => _value;


    public DmsProperty Update(Expression value)
    {
        SetChildNullableField(ref _value, Expression.IsEmptyExpression, value);
        return this;
    }


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, NameIdentifier, Value);
    }
}


public static partial class NodeFactory
{
    public static DmsProperty CreateDMSProperty(SyntaxNode? parent, Identifier name, Expression? value)
    {
        DmsProperty property = new(name, parent);
        if (value != null)
        {
            property.Update(value);
        }

        return property;
    }
}